package com.jackstraw.jack_base.mq.common.aspect.contextholder;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.jackstraw.jack_base.util.StringUtil;

/**
 * 对MQ的ContextHolder
 */
public class MqContextHolder {

    /**
     * serverName
     */
    private static final ThreadLocal<String> serverNameContextHolder = new TransmittableThreadLocal<>();


    /**
     * 清空serverNameContextHolder
     */
    public static void clearServerName() {
        serverNameContextHolder.remove();
    }


    /**
     * 设置serverNameContextHolder
     *
     * @param serverName
     */
    public static void setServerName(String serverName) {
        if (StringUtil.StringUtilsBylang3.isNotEmpty(serverName)) {
            serverNameContextHolder.set(serverName);
        }
    }


    /**
     * 得到serverNameContextHolder
     */
    public static String getServerName() {
        return serverNameContextHolder.get();
    }


}
